home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1631 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.staffs.ac.uk!bs47c!cm4bctrd
  2. From: cm4bctrd@bs47c.staffs.ac.uk (Wildfire)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: realloc->free?
  5. Date: 15 Jan 1996 19:12:31 GMT
  6. Organization: Staffordshire University
  7. Message-ID: <4de8uv$48j@bs33n.staffs.ac.uk>
  8. References: <4daa2e$oh5@axe.netdoor.com>
  9. NNTP-Posting-Host: bs47c.staffs.ac.uk
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. On Sun, 14 Jan 1996 07:08:29 GMT, Eric Sargent looked thoughtfully at the keyboard and typed...
  13. :     This is probably a dumb question, but I can't find any specific or
  14. : exact information about this.  Given this:
  15.  
  16. : char *a, *b;
  17.  
  18. : a = malloc(10);
  19. : ...
  20. : /*
  21. :     later we need to increase the size
  22. : */
  23. : ...
  24. : b = realloc(a, 100);
  25.  
  26. :     Now let's say realloc had to move the data so a != b.  Does realloc
  27. : free the memory previously pointed to by a or should it be explicitly
  28. : freed if realloc returns a new location?  I checked the FAQ, but there
  29. : was nothing specific about realloc.  Thanks for any information.
  30.  
  31. Right.  I could be wrong in what I'm about to say, but I *think* this is 
  32. correct.
  33.  
  34. If you think about it, there is no need for realloc() to move the *start* 
  35. of the allocated memory - it may need to make a link between the end of 
  36. the original memory block and the start of an extension block, but that's 
  37. different.
  38.  
  39. So b is either going to be NULL or a.
  40.  
  41. realloc() does no free()ing, as far as I know, since the contents of 
  42. memory are unchanged.
  43.  
  44. I would really like someone who properly knows about this to confirm or 
  45. correct what I'm saying.
  46.  
  47. Wildfire :-)
  48.  
  49. -----------------------------------------------------------------------------
  50. "Oh God could it be the weather? - oh God - why am I here?  If love isn't 
  51. forever...and it's not the weather...*whisper* - hand me my leather..."
  52.  
  53. Member of the AEL fan club :-)
  54.  
  55. Knight of The Rose, loyal follower of The Sea...(mud.veda.is 4000)
  56. -----------------------------------------------------------------------------
  57.